import React, { Component } from 'react'
import {connect} from 'dva'
import { Form, Table, Button, Select, Tag ,Modal} from 'antd';
import {routerRedux} from "dva/router"
const { confirm } = Modal;
const { Option } = Select
const mapStateTopProps = (state) => state.repository

@connect(mapStateTopProps)
class Interview extends Component {
    state = {
        loading: true
    }
    componentDidMount () {
        this.getInterviewList()
    }
     del=(payload)=>{
      this.props.dispatch({
        type: 'repository/delInterview',
        payload
      })
      confirm({
        title: '确定要删除吗?',
        content: 'Some descriptions',
        okText: '确定',
        okType: 'danger',
        cancelText: '取消',
        onOk() {
          // this.props.dispatch({
          //   type: 'repository/delInterview',
          //    payload
          // })
        },
        onCancel() {
          console.log('Cancel');
        },
      });
     }
     btn_create=()=>{
      console.log(this)
      window.location.href="/#/repository/create"
     }
    getInterviewList = (payload = {}) => {
        console.log(payload)
        this.setState({
          loading: true
        }, () => {
          this.props.dispatch({
            type: 'repository/getInterviewList',
            payload
          }).then(() => {
            this.setState({
              loading: false
            })
          })
        })
      }
    get tableColumns () {
        return [
          {
            title: '题目',
            dataIndex: 'title',
            key: 'title',
            render: text => <a>{text}</a>,
          },
          {
            title: '添加人',
            dataIndex: 'user_name',
            key: 'user_name',
          },
          {
            title: '类型',
            dataIndex: 'exam_name',
            key: 'exam_name',
            render: (text, record, index) => {
              return (
                <React.Fragment>

                  <Tag key={record.questions_type_id}>{record.questions_type_text}</Tag>
                 
                </React.Fragment>
              )
            }
          },
          {
            title: '操作',
            dataIndex: 'address',
            key: 'address',
            render: (text, record, index) => {
              return (
                <React.Fragment>
                  <a onClick={()=>this.del()} style={{ marginRight: 16 }}>删除</a>
    
                  <a style={{ marginRight: 16 }}>编辑</a>
                </React.Fragment>
              
              )
            }
          },
        ]
      }
    render() {
      console.log(this.props)
        const {
            getInterview, // 试题类型
            getInterviewType, // 所有课程
            examType, // 考试类型
            InterviewList
          } = this.props
        return (
            <div>
              <div className="filter-head">
              <Form
                    layout="inline" 
                    initialValues={{
                    questions_type_id: '',

                    }}
                    onFinish={this.getInterview}
                >
                    <Form.Item label="类型" name="questions_type_id">
                    <Select style={{ width:"224px", }}>
                        <Option value="" checked key={1}>不限</Option>
                            {
                              getInterviewType.map(item => <Option value={item.questions_type_id} key={item.questions_type_id}>{item.questions_type_text}</Option>)
                            }
                    </Select>
                    </Form.Item>
                    <Form.Item>
                       <Button type="primary" htmlType="submit" style={{ width:"120px" ,marginLeft:"600px" }}>查询</Button>
                    </Form.Item>
                    
                    <Form.Item>
                       <Button type="primary" onClick={this.btn_create} htmlType="submit" style={{ width:"120px" ,marginLeft:"880px" }}>添加面试题</Button>
                    </Form.Item>
                </Form>
                
              </div>
              <div class="table-content">
                <Table loading={this.state.loading} columns={this.tableColumns} dataSource={getInterview.data} />
                </div>
            </div>
        );
    }
}
export default Interview